#include <stdio.h>
#include <pthread.h>
#include <roboMoMo.h>

#define CONF_SIZE 4

// The following constants are for referencing devices in config array
// Their value is their index in the array

#define MOTOR0	0
#define MOTOR1	1
#define SERVO0	2
#define BUZZER0 3

int main(void)
{
	int i;

	// The config array is an array of structs and is initialized as such
	// roboMoMo simply makes referencing the device files pretty but the
	// device files used by the drivers must be given in the config

	struct robo_dev config[CONF_SIZE] = {
		{ .value_file = "/sys/devices/msc0/motor0/value", .type = motor_type},
		{ .value_file = "/sys/devices/msc0/motor1/value", .type = motor_type},
		{ .value_file = "/sys/devices/msc0/servo0/value", .type = servo_type},
		{ .value_file = "/sys/devices/msc0/buzzer0/value", .type = buzzer_type}
	};

	// After the config is set using set config simply changing the array
	// will not change the config as the array is duplicated by setConfig

	setConfig(config, CONF_SIZE);

	// When referencing devices with roboMoMo the first argument is always
	// the index of the device in the config array

	setMotorValue(MOTOR0, 90);
	setMotorValue(MOTOR1, 90);

	sleep(3);

	setMotorValue(MOTOR0, 90);
	setMotorValue(MOTOR1, -90);

	sleep(1);

	setMotorValue(MOTOR0, 90);
	setMotorValue(MOTOR1, 90);

	sleep(3);

	setMotorValue(MOTOR0, 0);
	setMotorValue(MOTOR1, 0);

	disableServo(SERVO0);

	return 0;
}
